package com.bookmanager.www.controller.mongodb;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: 风离
 * @Date: 2021/12/09/23:23
 * @Description: 会员浏览记录
 */

import com.bookmanager.www.common.utils.Result;
import com.bookmanager.www.entity.mongodb.MemberReadHistory;
import com.bookmanager.www.service.MemberReadHistoryRepository;
import com.bookmanager.www.service.MemberReadHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Controller
@Api(tags ="会员商品浏览记录管理")
@RequestMapping("/member/readHistory")
public class MemberReadHistoryController {
    @Resource
    private MemberReadHistoryService memberReadHistoryService;

    @Resource
    private MemberReadHistoryRepository memberReadHistoryRepository;

    @ApiOperation("创建浏览记录")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public Result create(@RequestBody MemberReadHistory memberReadHistory) {

        int count = memberReadHistoryService.create(memberReadHistory);
        if (count > 0) {
            return Result.succ("创建成功",count);
        } else {
            return Result.fail("创建失败","");
        }
    }

    @ApiOperation("删除浏览记录")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") List<String> ids) {
        int count = memberReadHistoryService.delete(ids);
        if (count > 0) {
            return Result.succ("删除成功",count);
        } else {
            return Result.fail("删除失败","");
        }
    }

    @ApiOperation("展示浏览记录")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Result list(Long memberId) {
        List<MemberReadHistory> memberReadHistoryList = memberReadHistoryService.list(memberId);

        return Result.succ("获取成功",memberReadHistoryList);
    }
}
